type Action<T extends string = string> = {
  type: T;
  [extraProps: string]: any;
};

interface HandlerType<S, A = Action> {
  [key: string]: (state: S, action: A) => S
}

/**
 * @function - 建议使用该方案
 * @description - reducer处理函数构建器
 * @param {T} preState - state
 * @param {H} handlers - reducer处理函数map集合
 * @returns {function} - reducer处理函数
 */
export const createReducer = <S>(
  preState: S,
  handlers: HandlerType<S>,
) => (state = preState, action: Action): S => {
    if (Object.prototype.hasOwnProperty.call(handlers, action.type)) {
      return handlers[action.type](state, action)
    }
    return state
  }
